#coding=utf-8

import unittest

class TestDesignPattern(unittest.TestCase):

    def test_factory(self):
        print 'test_factory'
        print '============================'
        import DaoFactory

        u1 = DaoFactory.dao_factory("User")
        u2 = DaoFactory.dao_factory("User")

        self.assertTrue(u1 == u2)

        u1.get(1)
        u1.update(1,1)
        u1.insert(1)
        u1.delete(1)

    def test_invaild_decorator(self):
        print 'test_invaild_decorator'
        print '============================'
        import DaoFactory
        import modeldecorator

        u1 = DaoFactory.dao_factory("User")
        print 'before decorator'
        print '========'
        u1.get(1)
        u1.update(1,1)
        u1.insert(1)
        u1.delete(1)

        u1 = modeldecorator.Invaildate(u1,dict(arg1="test1"))

        print 'after decorator'
        print '========'
        u1.get(1)
        u1.update(1,1)
        u1.insert(1)
        u1.delete(1)

        print 'after two decorator'
        u1 = modeldecorator.Pagination(u1,dict(per_page_num ="10"))
        u1.all()

        u1 = modeldecorator.Invaildate(u1,dict(arg2="test2"))
        print 'after three decorator'
        print '========'
        u1.get(1)
        u1.update(1,1)
        u1.insert(1)
        u1.delete(1)

    def test_decorator_factory(self):
        print 'test_decorator_factory'
        print '======================================'
        import DaoFactory

        u1 = DaoFactory.dao_decorator_factory('Todo')
        u1.get(1)
        u1.update(1,1)
        u1.insert(1)
        u1.delete(1)
        u1.all()


if __name__ == "__main__":
    unittest.main()
